using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace InputProductForm
{
    class TProduct
    {
        UTLDB.UTLDB _cn = new UTLDB.UTLDB();
        public int InsertShell(InfoShell info)
        {
            int id = _cn.ExecuteInsert("sp_InserttblShell",
               new string[] { "@Weight", "@Price", "@IDMaterial", "@UnitID", "@Change", "@IdPriceUnit", "@GoldType", "@Source" },
               new object[] { info.Weight, info.Price, info.IDMaterial, info.UnitID, info.Change, info.IdPriceUnit,info.GoldType, info.Source });
            return id;

        }
        public int InsertSeed(InfoSeed info)
        {
            int id = _cn.ExecuteInsert("sp_InserttblSeed",
              new string[] { "@Name", "@Size", "@IDUnit", "@Price", "@DatePrice", "@Type", "@Quality" },
              new object[] { info.Name, info.Size, info.IDUnit, info.Price, info.DatePrice, info.Type, info.Quality });
            return id;
        }
        public int InsertProduct(InfoProduct info)
        {
            int id = _cn.ExecuteInsert("sp_InserttblProduct",
                new string[] { "@Name", "@Barcode", "@IDCat", "@IDShell", "@IDSeedLarge", "@NumberSeedLarge", "@IDSeedSmall", "@NumberSeedSmall", "@TienCong", "@Status", "@CreateDate" },
                new object[] { info.Name, info.Barcode, info.IDCat, info.IDShell, info.IDSeedLarge, info.NumberSeedLarge, info.IDSeedSmall, info.NumberSeedSmall, info.TienCong, info.Statue, info.CreateDate });
            return id;
        }
        public int InsertPriceUnit(InfoPriceUnit info)
        {
            int id = _cn.ExecuteInsert("usp_InserttblPriceUnit",
              new string[] { "@IdType", "@IdUnit", "@Price", "@Date","@IdMaterial" },
              new object[] { info.IdType, info.IdUnit, info.Price, info.Date, info.IdMaterial });
            return id;
        }
        public void UpdatePriceUnit(InfoPriceUnit info)
        {
            int id = _cn.ExecuteNonQuery("usp_UpdatetblPriceUnit",
                new string[] { "@ID", "@IdType", "@IdUnit", "@Price", "@Date" },
                new object[] { info.ID, info.IdType, info.IdUnit, info.Price, info.Date });

        }
        public DataTable SelectPriceUnit(int idType, int idUnit, int idMaterial)
        {
            DataTable data = _cn.GetDataByStoredProcedure("sp_SelectId_tblPriceUnit",
               new string[] { "@IdType", "@IdUnit","@IdMaterial" },
               new object[] { idType, idUnit, idMaterial });
            return data;
        }
        public int InsertProductSeed(int idPro, int idSeed, int num)
        {
            int id = _cn.ExecuteInsert("sp_InserttblProductSeed",
              new string[] { "@IdPro", "@IdSeed","@Num" },
              new object[] { idPro, idSeed,num });
            return id;
        }
        public void UpdateSeed(InfoSeed info)
        {
            int id = _cn.ExecuteNonQuery("sp_UpdatetblSeed",
            new string[] { "@ID", "@Name", "@Size", "@IDUnit", "@Price", "@DatePrice" },
            new object[] { info.Id, info.Name, info.Size, info.IDUnit, info.Price, info.DatePrice });
        }
        public DataTable SelectSeed(string Name, string _Type, string Quality)
        {
            DataTable data = _cn.GetDataByStoredProcedure("sp_SelecttblSeed",
                new string[] { "@Name", "@Type", "@Quality" },
                new object[] { Name, _Type, Quality });
            return data;
        }
        public DataTable SelectMetarial()
        {
            DataTable data = _cn.GetDataBySQL("SELECT * FROM [tblMaterial] where Active=1");
            return data;
        }
        public DataTable SelectUnit()
        {
            DataTable data = _cn.GetDataBySQL("SELECT * FROM [tblUnit] where Active=1");
            return data;
        }
        

        public DataTable GetBarcode(int idCat)
        {
            DataTable data = _cn.GetDataBySQL("SELECT Barcode FROM [tblProduct] where IDCat=" + idCat);
            return data;
        }
        public DataTable LoadProductWithStatus(int status)
        {

            DataTable data = new DataTable();
            data = _cn.GetDataByStoredProcedure("sp_SelecttblProduct_status",
               new string[] { "@Status" },
               new object[] { status }
                );
            return data;
        }

        public DataTable SelectSeedByProduct(int idPro) {
            DataTable data = _cn.GetDataByStoredProcedure("sp_SelecttblSeed_byProduct",
                         new string[] { "@idPro"},
                         new object[] {idPro});
            return data;
        }

        //delete;
        public void DeleteSeed(int id) { 
        
        }
        public void DeletePr_Seed(int idpr) { 
  

        }
        public void DeleteShell(int idPro) { 
        }
        public void DeleteProduct(int idPr) {
            try
            {
                _cn.ExecuteNonQuery("sp_Delete_tblProduct",
                    new string[] { "@ID" },
                    new object[] { idPr });
            }
            catch (Exception e) {
                Console.Write(e.Message);
            
            }
        }

    }
}
